package com.example.aspect;


import com.example.Utils.UserHolder;
import com.example.pojo.Constants.UserRedisConstants;
import com.example.pojo.Result;
import com.example.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class LoginCheckAspect {

    @Autowired
    private RedisTemplate redisTemplate;

    @Pointcut("execution(* com.example.Controller.*.*(..)) &&  @annotation(com.example.annotation.LoginCheck)")
    public void autoLogPointCut(){}

    @Before("autoLogPointCut()")
    public void check(JoinPoint joinPoint){
        log.info("开始进行登录检查-------------");

//        User user = UserHolder.getUser();
//        log.info("当前登录用户：{}",user.getUsername());
//        Object o = redisTemplate.opsForValue().get(UserRedisConstants.USER_LOGIN+user.getId());
////        if(o != null){
////            return pjp.proceed();
////        }
////
////        return Result.error("请登录进行操作");
//        if(o == null){
//            log.info("请登录进行操作");
//        }
    }

}
